﻿namespace LogManager.Gui.Converters
{
    using System;
    using System.Windows.Data;

    public class SubstractFromConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                //  var par = VisualTreeHelper.GetParent((DependencyObject)value);
                var val = System.Convert.ToInt32(value);
                var sub = System.Convert.ToInt32(parameter);
                var result = val - sub;
                return result > 0 ? result : 0;
            }
            catch (Exception)
            {
                return 0;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
